/********************************** (C) COPYRIGHT *******************************
 * File Name          : main.c
 * Author             : WCH
 * Version            : V1.0.0
 * Date               : 2021/06/06
 * Description        : Main program body.
 *********************************************************************************
 * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
 * Attention: This software (modified or not) and binary are used for
 * microcontroller manufactured by Nanjing Qinheng Microelectronics.
 *******************************************************************************/

/*
 *@Note
 USART Print debugging routine:
 USART1_Tx(PA9).
 This example demonstrates using USART1(PA9) as a print debug port output.

*/

#include "debug.h"


/* Global typedef */

/* Global define */

/* Global Variable */

void usb_dc_low_level_init (void) {
    RCC_USBCLK48MConfig (RCC_USBCLK48MCLKSource_USBPHY);
    RCC_USBHSPLLCLKConfig (RCC_HSBHSPLLCLKSource_HSE);
    RCC_USBHSConfig (RCC_USBPLL_Div2);
    RCC_USBHSPLLCKREFCLKConfig (RCC_USBHSPLLCKREFCLK_4M);
    RCC_USBHSPHYPLLALIVEcmd (ENABLE);
    RCC_AHBPeriphClockCmd (RCC_AHBPeriph_USBHS, ENABLE);

    NVIC_EnableIRQ (USBHS_IRQn);
}

/*********************************************************************
 * @fn      main
 *
 * @brief   Main program.
 *
 * @return  none
 */
int main (void) {
    NVIC_PriorityGroupConfig (NVIC_PriorityGroup_2);
    SystemCoreClockUpdate();
    Delay_Init();
    USART_Printf_Init (921600);
    printf ("SystemClk:%d\r\n", SystemCoreClock);
    printf ("ChipID:%08x\r\n", DBGMCU_GetCHIPID());
    printf ("This is printf example\r\n");

	// extern void cdc_acm_init(uint8_t busid, uintptr_t reg_base);
	// cdc_acm_init(0, USBHS_BASE);

	// extern void cdc_acm_data_send_with_dtr_test(uint8_t busid);
    // while (1) {
	// 	cdc_acm_data_send_with_dtr_test(0);
    // }

	// extern void audio_v1_init(uint8_t busid, uintptr_t reg_base);
	// extern void audio_v1_test(uint8_t busid);
	// audio_v1_init(0, USBHS_BASE);

	// while (1) {
	// 	audio_v1_test(0);
	// }

	extern void cdc_acm_hid_msc_descriptor_init(uint8_t busid, uintptr_t reg_base);
	extern void cdc_acm_data_send_with_dtr_test(uint8_t busid);

	cdc_acm_hid_msc_descriptor_init(0, USBHS_BASE);
	while (1) {
		cdc_acm_data_send_with_dtr_test(0);
	}
}
